#coding=utf-8
import unittest
from appium import webdriver
from selenium import webdriver
from time import sleep
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.support.ui import WebDriverWait
from Public.BasePage import element_Oprate
from Public.BasePage import BasicAction
from Public import BaseConstant
from  Public import BasePage

#实例化基础数据
element_oprate_instance = element_Oprate()
basicAction = BasicAction()
Server_Url_Paramter_instances = BaseConstant.Server_Url_Paramter
Login_egova_Paramter_instances = BaseConstant.Login_egova_Paramter

class login_factory():

    def modify_server_address(self,driver,server_url,file_path):
        element_oprate_instance.element_click(Server_Url_Paramter_instances.setting_butoon,file_path)
        element_oprate_instance.elemet_clear(Server_Url_Paramter_instances.setting_edit,file_path)
        element_oprate_instance.element_send_keys(Server_Url_Paramter_instances.setting_edit,server_url.decode("utf-8"),file_path)

        element_oprate_instance.element_save_pic(file_path,'modify_server_address')
        element_oprate_instance.element_click(Server_Url_Paramter_instances.setting_ok_button, file_path)

    def login_system(self, driver, user_name, user_pwd, file_path):
        try:
            #输入用户名
            element_oprate_instance.element_send_keys(Login_egova_Paramter_instances.login_txtUsername,user_name.decode("utf-8"), file_path)
            BasePage.Base.driver.find_element_by_id(Login_egova_Paramter_instances.login_txtUsername[2]).send_keys('test')
            sleep(2)
            #输入密码
            element_oprate_instance.element_click(Login_egova_Paramter_instances.login_txtPassword, file_path)
            element_oprate_instance.element_send_keys(Login_egova_Paramter_instances.login_txtPassword,user_pwd.decode("utf-8"), file_path)
            #勾选保存密码
            # element_oprate_instance.element_click(Login_egova_Paramter_instances.save_pwd,file_path)
            #点击登录按钮
            element_oprate_instance.element_click(Login_egova_Paramter_instances.login_btnSubmit, file_path)
            sleep(5)

            if element_oprate_instance.element_display_commit(Login_egova_Paramter_instances.home_tab_item_icon, file_path):
                print("login success.....")
                element_oprate_instance.element_save_pic(file_path, 'login_successful')
            else:
                print("login failed.....")

        except WebDriverException, el_error:
            element_oprate_instance.element_save_pic(file_path, 'login_failed')
            print el_error
            raise
if __name__ == '__main__':
	unittest.main()

